//
//  HistoryBace.m
//  厚积薄发
//
//  Created by 焦钟培 on 15-1-8.
//  Copyright (c) 2015年 侯振兴. All rights reserved.
//

#import "HistoryBace.h"
#import "HistoryModel.h"
#import "DB.h"

@implementation HistoryBace
+ (void)insertIntoHistoryWithHistoryModel:(HistoryModel *)model
{
    sqlite3 *dbpoint = [DB openDB];
    NSString *str = [NSString stringWithFormat:@"insert into history(history_tit) values('%@')",model.history_tit];
    int result = sqlite3_exec(dbpoint, [str UTF8String], nil, nil, nil);
    if (result == SQLITE_OK) {
        
    }else{
        
    }
}
+ (void)deleteFromHistoryWithHistory_tit:(NSString *)history_tit
{
    sqlite3 *dbpoint = [DB openDB];
    NSString *str = [NSString stringWithFormat:@"delete from history where history_tit='%@'",history_tit];
    int result = sqlite3_exec(dbpoint, [str UTF8String], nil, nil, nil);
    if (result == SQLITE_OK) {
        
    }else{
        
    }
}
+ (NSArray *)selectAllHistory
{
    sqlite3 *dbpoint = [DB openDB];
    sqlite3_stmt *stmt = nil;
    NSString *selectStr = @"select history_tit from history";
    int result = sqlite3_prepare_v2(dbpoint, [selectStr UTF8String], -1, &stmt, nil);
    NSMutableArray *array = [NSMutableArray array];
    if (result == SQLITE_OK) {
        while (sqlite3_step(stmt) == SQLITE_ROW) {
            const unsigned char *tit = sqlite3_column_text(stmt, 0);
            NSString *history_tit = [NSString stringWithUTF8String:(const char *)tit];
           HistoryModel *model = [HistoryModel historyWithHistory_tit:history_tit];
            [array addObject:model];
        }
        
    }
    sqlite3_finalize(stmt);
    return array;
}


@end
